package com.hangxiang.approval.controller;

import com.hangxiang.approval.common.*;
import com.hangxiang.approval.entity.Role;
import com.hangxiang.approval.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Role)表控制层
 *
 * @author makejava
 * @since 2020-11-23 18:06:45
 */
@RestController
@RequestMapping("role")
@Api(tags = "角色相关功能")
public class RoleController {
    /**
     * 服务对象
     */
    @Resource
    private RoleService roleService;

    /**
     * 通过主键查询单条数据
     *
     * @param common 主键
     * @return 单条数据
     */
    @PostMapping("selectToRole")
    @ApiOperation(value = "通过主键查询单条数据")
    @ResponseBody
    public ResultBean selectToRole(@RequestBody @Validated RoleCommon common) {
        return ResultBean.success(roleService.queryByRoleId(common));
    }

    /**
     * 新增数据
     *
     * @param roleInsertCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("insertRole")
    @ApiOperation(value = "添加数据")
    @ResponseBody
    public ResultBean insert(@RequestBody @Validated RoleInsertCommon roleInsertCommon) {
        return ResultBean.success(roleService.insertRole(roleInsertCommon));
    }

    /**
     * 新增数据
     *
     * @param roleUpdateCommon 实例对象
     * @return 实例对象
     */
    @PostMapping("updateRole")
    @ApiOperation(value = "修改数据")
    @ResponseBody
    public ResultBean update(@RequestBody @Validated RoleUpdateCommon roleUpdateCommon) {
        return ResultBean.success(roleService.updateRole(roleUpdateCommon));
    }


}